/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2009 - 2012 Luca Mingardi.
 *
 * This file is part of jeeObserver.
 *
 * JeeObserver is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * JeeObserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package jeeobserver.server.settings;

import jeeobserver.ActionObserver;
import jeeobserver.server.settings.Condition.BooleanCondition;
import jeeobserver.server.settings.Condition.NumberCondition;
import jeeobserver.server.settings.Condition.TextCondition;
import jeeobserver.server.settings.Condition.TimePeriodCondition;

/**
 * The Class ActionExclusionRule.
 *
 * @author Luca Mingardi
 * @version 4.0
 */
public class ActionExclusionRule extends Rule {

	 /** The Constant serialVersionUID. */
	 private static final long serialVersionUID = 40L;

	 /** The category condition. */
	 private NumberCondition categoryCondition;

	 /** The project condition. */
	 private TextCondition projectCondition;

	 /** The element name condition. */
	 private TextCondition elementNameCondition;

	 /** The principal condition. */
	 private TextCondition principalCondition;

	 /** The exception throwed condition. */
	 private BooleanCondition exceptionThrowedCondition;

	 /** The cpu usage condition. */
	 private TimePeriodCondition cpuUsageCondition;

	 /** The duration condition. */
	 private TimePeriodCondition durationCondition;

	 public boolean isObserverInRule(ActionObserver observer) {



			if (super.isObserverInRule(observer)) {

				 if ((this.categoryCondition == null) || this.categoryCondition.checkValue(observer.getCategory())) {
						if ((this.projectCondition == null) || this.projectCondition.checkValue(observer.getProject())) {
							 if ((this.elementNameCondition == null) || this.elementNameCondition.checkValue(observer.getName())) {
									// Check CPU usage
									if ((this.cpuUsageCondition == null) || this.cpuUsageCondition.checkNanosValue(observer.getCpuNanos())) {
										 // Check duration
										 if ((this.durationCondition == null) || this.durationCondition.checkNanosValue(observer.getTimeNanos())) {
												// Exception NOT throwed
												if ((observer.getException() == null)) {
													 if ((this.exceptionThrowedCondition == null) || this.exceptionThrowedCondition.checkValue(false)) {
															return true;
													 }
												} else {
													 if ((this.exceptionThrowedCondition == null) || this.exceptionThrowedCondition.checkValue(true)) {
															return true;
													 }
												}
										 }
									}
							 }
						}
				 }
			}

			return false;
	 }

	 /**
	  * Gets the category condition.
	  *
	  * @return the category condition
	  */
	 public NumberCondition getCategoryCondition() {
			return this.categoryCondition;
	 }

	 /**
	  * Sets the category condition.
	  *
	  * @param categoryCondition the new category condition
	  */
	 public void setCategoryCondition(NumberCondition categoryCondition) {
			this.categoryCondition = categoryCondition;
	 }

	 /**
	  * Gets the cpu usage condition.
	  *
	  * @return the cpu usage condition
	  */
	 public TimePeriodCondition getCpuUsageCondition() {
			return this.cpuUsageCondition;
	 }

	 /**
	  * Sets the cpu usage condition.
	  *
	  * @param cpuUsageCondition the new cpu usage condition
	  */
	 public void setCpuUsageCondition(TimePeriodCondition cpuUsageCondition) {
			this.cpuUsageCondition = cpuUsageCondition;
	 }

	 /**
	  * Gets the duration condition.
	  *
	  * @return the duration condition
	  */
	 public TimePeriodCondition getDurationCondition() {
			return this.durationCondition;
	 }

	 /**
	  * Sets the duration condition.
	  *
	  * @param durationCondition the new duration condition
	  */
	 public void setDurationCondition(TimePeriodCondition durationCondition) {
			this.durationCondition = durationCondition;
	 }

	 /**
	  * Gets the element name condition.
	  *
	  * @return the element name condition
	  */
	 public TextCondition getElementNameCondition() {
			return this.elementNameCondition;
	 }

	 /**
	  * Sets the element name condition.
	  *
	  * @param elementNameCondition the new element name condition
	  */
	 public void setElementNameCondition(TextCondition elementNameCondition) {
			this.elementNameCondition = elementNameCondition;
	 }

	 /**
	  * Gets the exception throwed condition.
	  *
	  * @return the exception throwed condition
	  */
	 public BooleanCondition getExceptionThrowedCondition() {
			return this.exceptionThrowedCondition;
	 }

	 /**
	  * Sets the exception throwed condition.
	  *
	  * @param exceptionThrowedCondition the new exception throwed condition
	  */
	 public void setExceptionThrowedCondition(BooleanCondition exceptionThrowedCondition) {
			this.exceptionThrowedCondition = exceptionThrowedCondition;
	 }

	 /**
	  * Gets the project condition.
	  *
	  * @return the project condition
	  */
	 public TextCondition getProjectCondition() {
			return this.projectCondition;
	 }

	 /**
	  * Sets the project condition.
	  *
	  * @param projectCondition the new project condition
	  */
	 public void setProjectCondition(TextCondition projectCondition) {
			this.projectCondition = projectCondition;
	 }

	 /**
	  * Gets the principal condition.
	  *
	  * @return the principal condition
	  */
	 public TextCondition getPrincipalCondition() {
			return this.principalCondition;
	 }

	 /**
	  * Sets the principal condition.
	  *
	  * @param principalCondition the new principal condition
	  */
	 public void setPrincipalCondition(TextCondition principalCondition) {
			this.principalCondition = principalCondition;
	 }
}
